//
//  MXSDisSearchView.swift
//  weibo
//
//  Created by 孙飞 on 15/12/7.
//  Copyright © 2015年 Sunfei. All rights reserved.
//

import UIKit

class MXSDisSearchView: UIView ,UITextFieldDelegate{

    @IBOutlet weak var cancelBtn: UIButton!
    @IBOutlet weak var fieldSpaceR: NSLayoutConstraint!
    @IBOutlet weak var textField: UITextField!
    
    @IBAction func cancleBtnClick(sender: UIButton) {
        
        textField .resignFirstResponder()
        
        self.fieldSpaceR.constant = 0
        UIView .animateWithDuration(0.5) { () -> Void in
            
            self.textField.layoutIfNeeded()
        }
    }
    
    class func searchView() -> MXSDisSearchView {
        return NSBundle.mainBundle().loadNibNamed("MXSDisSearchView", owner: nil, options: nil).last as! MXSDisSearchView
    }
    
    // 与 代码 创建控件 有关????
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    override func awakeFromNib() {
        
    }
    
    //从xib、sb中加载视图 需要实现这个方法
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    
    func textFieldDidBeginEditing(textField: UITextField) {
        
        self.fieldSpaceR.constant = self.cancelBtn.frame.width
        UIView .animateWithDuration(0.5) { () -> Void in
            
            self.textField.layoutIfNeeded()
        }
    }

}
